import { _decorator, Component, Node, Button } from 'cc';
import { BasePanel } from '../../../../scripts/libs/ui/BasePanel';
import { BindButton } from '../../../../scripts/libs/rxjs/cc3/BindButton';
import { gm } from '../../../../scripts/managers/GameManager';
import { GameKey } from '../../../../scripts/managers/SubgameConfig';
import { DialogPanel } from '../DialogPanel/DialogPanel';
import { subgame001 } from '../../UIConfig';
import { game001 } from '../../Game001Manager';
import { lm } from '../../../../ab_lobby/scripts/LobbyManager';
const { ccclass, property } = _decorator;

@ccclass('MainPanel')
export class MainPanel extends BasePanel {

    @property(Button)
    backButton: Button = null;

    @property(Button)
    dialogButton: Button = null;

    useObserves() {
        return [
            BindButton(this.backButton).subscribe(this.backbuttonClicked.bind(this)),
            BindButton(this.dialogButton).subscribe(this.dialogButtonClicked.bind(this))
        ];
    }

    backbuttonClicked() {
        this.log('backButtonClicked');
        gm.leaveGameCommand.execute(GameKey.subgame001);
    }

    dialogButtonClicked() {
        this.log('dialogButtonClicked');
        DialogPanel.StartProcess(null, null, game001.uiRoot).subscribe(_ => {
            this.log('dialogPanel closed', _);
            lm.frontTip.show(`result: ${_.result}`).subscribe();
        });
    }
}
